package com.itheima.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

//@WebFilter("/*")//拦截路径所有
@Slf4j
public class DemoFilter implements Filter {

    /**
     * 初始化过滤器 只执行一次
     *
     * @param filterConfig
     * @throws ServletException
     */
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
       log.info("DemoFilter过滤器初始化...init");
    }

    /**
     * 过滤器执行方法
     *
     * @param servletRequest
     * @param servletResponse
     * @param filterChain
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("DemoFilter过滤器执行了...doFilter");
        // 放行
        filterChain.doFilter(servletRequest, servletResponse);
    }

    /**
     * 销毁过滤器
     */
    @Override
    public void destroy() {
        log.info("DemoFilter过滤器销毁...destroy");
    }
}
